package com.dycx.food.enums;

import lombok.Getter;

import java.util.*;

/**
 * 商品排序枚举
 */
@Getter
public enum GoodsSortEnum {
    DEFAULT(1, "综合"),
    SALES_VOLUME(2, "销量");

    private final Integer code;
    private final String name;

    GoodsSortEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public static String converter(Integer code) {
        return Arrays.stream(values()).filter(en -> en.code.equals(code)).findAny().orElse(DEFAULT).getName();
    }

    /**
     * 转为数据
     *
     * @return 枚举对象数组
     */
    public static List<Map<String, Object>> getList() {
        List<Map<String, Object>> list = new ArrayList<>();
        for (GoodsSortEnum item : GoodsSortEnum.values()) {
            Map<String, Object> map = new HashMap<>();
            map.put("code", item.getCode().toString());
            map.put("name", item.getName());
            list.add(map);
        }
        return list;
    }
}
